		
        <script type="text/javascript" src="<?php $this->path('js/ui/ui.dialog.js');?>"></script>
		<script type="text/javascript" src="<?php $this->path('js/ui/ui.autocomplete.js');?>"></script>
        <script type="text/javascript" src="<?php $this->path('js/selectBox.js');?>"></script>
		<script type="text/javascript" src="<?php $this->path('js/checkBox.js');?>"></script>
		<script type="text/javascript" src="<?php $this->path('js/radio.js');?>"></script>
		<style>
		.calc-btn{width:50px !important;height:50px !important;margin: 0 10px 10px 0 !important;-webkit-transition: all .5s ease;-moz-transition: all .5s ease;-o-transition: all .5s ease;}
		.niceCheck input{display:none;}
		.tdiscount{text-decoration:line-through;color:#cacaca;font-size:14px;}
		.tdiscount:after{content:')';}
		.tdiscount:before{content:'(';}
		#search-btn{width: 25px;height: 25px;background-image:url('<?php $this->path('img/bg_search.png');?>');background-repeat:no-repeat;background-position:center;text-decoration:none;position:absolute;background-color:#fff;}
		#search-btn:hover{background-image:url('<?php $this->path('img/bg_search_h.png');?>');}
		.panel-open{left:0px !important;}
		.trselected, .searches:hover{background:#FFFAD9;cursor:pointer}
		</style>
		<section id="main" class="entire_width">
    		<div class="container_12">
			   <?php $this->getPageCrumb(); ?> 
        		<div id="content" class="grid_9" style="min-height:400px;float:left;width:670px;">
        			<h1 class="page_title">Sales Register</h1>
        	      	<div class="clear"></div>
					<br />
        			<!--<div class="options">
        				<div class="grid-list">
							<div class="sort">
            					<span class="categorize">&emsp;Category</span>
            					<select title="category">
            						<option>Pencil</option>
            						<option>Paper</option>
            					</select>
            			    
            					<a class="sort_up" flag="1">&#8595;</a>
        					</div><!-- .sort --
        				</div><!-- .grid-list --
        			</div><!-- .options --
					<div id="renderer"></div>				
        			<div class="clear"></div>
				</div>-->
				
				<div id="content2" class="grid_9" style="min-height:400px;float:left;width:670px;margin-top:-10px">  
					<form class="form_style" style="padding:0px;">
						<span style="position:relative;display:inline-block;margin:9px">
							<input type="checkbox" id="togqty" class="niceCheck" value=""><span style="position:absolute;display:inline-block;width: 135px;top: -3px;text-indent:5px">Toggle Item Amount</span>
						</span>
						<input type="button" value="Delete" style="float:right;" id="itemdel" />
						<input type="text" autocomplete="off" id="search-box" style="width:40%;float:left;" placeholder="Enter Barcode" /> 
					</form>  	      
					<div class="clear"></div>
        			<table style="height:400px;margin-top:5px;" id="list-item">
						<thead>
							<tr style="display:block;position:relative;">
    							<th style="width: 40px" id="chksel"><input type="checkbox" class="niceCheck"  /></th>
    							<th style="width: 30px;">Barcode</th>
    							<th style="width: 250px;">Description</th>
    							<th style="width: 100px;">Unit</th>
    							<th style="width: 50px;">Qty</th>
    							<th style="width: 100px;">Price</th>
    							<th style="width: 100px;">Amount</th>
							</tr>
						</thead>
						<tbody style="height: 300px;overflow: auto;display: block;width:100%">
						</tbody>
					</table>	
        			<div class="clear"></div>
				</div>
				
			<div id="sidebar" class="grid_3" style="float:right;width:320px;top: 0px;position: absolute;z-index: 1001;">
				<div style="border: 1px solid #ccc;margin-top: 10px;padding: 10px;width: 340px;margin-left: -40px;
text-align: right;height: 70px;background:#fff;">
				<h4 style="font-size:40px;margin-bottom:-10px;">&#8369;<span></span><span class="totalprc">0.00</span></h4>
				<small>Total Items: &emsp; <span class="totalqty">0</span></small>
				</div>
				<form class="form_style registed">
					<select id="sale-type">
						<option value="0">Retail</option>
						<option value="1">Wholesale</option>
					</select>
					<hr class="ccustomer" style="margin:10px;display:none;" />
					<strong class="ccustomer" id="customer" style="display:none;">Customer</strong>
					<br class="ccustomer" />
					<input class="ccustomer" type="text" id="ccustomer2" style="text-align:center;background:#fff;display:none;width: 70%;" value="" />
					<input class="ccustomer" type="button" value="Add" style="width: 50px;display: inline-block;float: right;margin-right: 2px;margin-top: 5px;display:none;" id="searchc" />
					<hr style="margin:10px" />
					<strong>Discount (&permil;)</strong>
					<input type="text" id="amtdisc" style="text-align:center;" value="0.00" />
					<hr style="margin:10px" />
					<strong>Cash (&#8369;)</strong><div class="clear"></div>
					<input type="text" id="amtpay" style="text-align:center;" value="0.00" />
					<strong>Change (&#8369;)</strong><div class="clear"></div>
					<input type="text" id="amtchange" value="0.00" style="text-align:center;" disabled/>
    				<!-- <span style="position:relative;display:inline-block;margin:9px">
    					<input type="checkbox" id="togprint" class="niceCheck" value="" checked="true"><span style="position:absolute;display:inline-block;width: 135px;top: -3px;text-indent:5px">Print Receipt</span>
    				</span>-->
					<input type="button" value="Payment" id="itempay" />
					<input type="button" value="Credit List" id="itemcredit" disabled />
        			<div class="clear"></div>
				</form>
				<div id="item_preview" title="Item Preview">
					<span>
						<img width="150" height="150" style="border:1px solid #e0e0e0" src="#" class="ease" />
					</span>
				</div>
				<div id="item_keypad" title="Keypad">
    				<form id="button-keys" class="form_style registed" style="width:240px;visibility:visible;margin-top:0">
        				<input type="button" value="7" class="calc-btn" />
        				<input type="button" value="8" class="calc-btn" />
        				<input type="button" value="9" class="calc-btn" />
        				<input type="button" value="&#8592;" class="calc-btn" style="float:right;" />
    									
            			<div class="clear"></div>
        				<input type="button" value="4" class="calc-btn" />
        				<input type="button" value="5" class="calc-btn" />
        				<input type="button" value="6" class="calc-btn" />
    						
            			<div class="clear"></div>
        				<input type="button" value="enter" class="calc-btn" style="float:right;height:110px !important;margin-bottom: -100px !important;"  />
        				<input type="button" value="1" class="calc-btn" />
        				<input type="button" value="2" class="calc-btn" />
        				<input type="button" value="3" class="calc-btn" />
    					
            			<div class="clear"></div>
        				<input type="button" value="0" class="calc-btn" />
        				<input type="button" value="00" class="calc-btn" />
        				<input type="button" value="." class="calc-btn" />
            			<div class="clear"></div>
        			</form>
				</div>
			</div>			
        	<div class="clear"></div>
		</section>
		<div id="search-panel" class="ease" style="position: fixed;border: 1px solid #e0e0e0;width: 450px;height: 400px;top: 100px;left: -451px;z-index: 9999;background: #fff;">
			<div class="options" style="margin-right:-1px;">
        		<div class="sort">
        			<select id="sel-category">
        				<option value=0>Select Categories</option>
						<?php foreach($categories as $category){ ?>
        				<option base="<?php echo $category['base_cat_id']; ?>" value="<?php echo $category['icid']; ?>"><?php echo $category['name']; ?></option>
						<?php } ?>
        			</select>
        			<a class="sort_up" flag="1">&#8595;</a>
        		</div><!-- .sort -->
				<div class="search-bar" style="z-index: 1;position: relative;">
					<input id="item-search" type="text" placeholder="Search for Item" style="width:215px;">
				</div>
        	</div><!-- .options -->
			<div style="position: absolute;top: -1px;right: -27px;width: 25px;height: 25px;border: 1px solid #e0e0e0;">
				<a href="#" id="search-btn" class="ease">&nbsp;</a>
			</div>
			<table style="height:100px;margin-top:-1px;">
				<thead>
					<tr style="display:block;position:relative;">
						<th style="width:250px;">Name</th>
						<th style="width:100px;">Price</th>
						<th style="width:100px;">Stock</th>
					</tr>
				</thead>
				<tbody style="height: 260px;overflow: auto;display: block;width:100%;" id="searches">
				</tbody>
			</table>
			<span style="position:absolute;display:inline-block;margin:9px;margin-top: 0px;bottom:-5px">
				<input type="checkbox" class="niceCheck" checked="true" id="hidesel"><span style="position:absolute;display:inline-block;width: 135px;top: -3px;text-indent:5px">Hide after selection</span>
			</span>
		</div>
		<div class="clear"></div>
		<div style="position:absolute;width:2in;height:auto;background:#fff;display:none;" id="receipt">
           	<style tyle="text/css">
            <!--
            @page { size:2.5in 5in; margin: 1cm; }
			.receipt { width:2.5in; height:auto; }
			.receipt .ui-text-center { text-align:center;display:block;width:100%; }
			.receipt, .receipt table { font-size:10px; font-family: Verdana; }
			.receipt small{ margin:0px;font-size: 12px; font-family: Calibri; }
			.receipt .clear{ display:block;clear:both; }
			.receipt .tdiscount{display:none;}
            -->
            </style>
			<div class="receipt">
    			<h4 class="ui-text-center" style="font-size: 12px;margin: 0px;">LVT GENERAL MERCHANDISE</h4>
    			<small class="ui-text-center">General Market, Nalasin,</small>
				<small class="ui-text-center">Balaoan, La Union</small>
    			<small class="ui-text-center">Ligaya B. Teofilo - Prop.</small>
    			<small class="ui-text-center">639189650271</small>
    			<table style="width:95%">
    				<thead>
    					<tr>
    						<th></th>
    						<th></th>
    						<th></th>
    						<th></th>
    					</tr>
    				</thead>
    				<tbody id="rcptitems">
						<tr>
							<td colspan="4">
								<span style="width:50px;text-align:right;display:inline-block;">Cashier:</span>
								<?php echo $login->userid; ?>
							</td>
						</tr>
						<tr>
							<td colspan="4">
								<span style="width:50px;text-align:right;display:inline-block;">Date:</span>
								<?php echo date("Y/m/d H:i:s") ?>
							</td>
						</tr>
						<tr>
							<td colspan="4">
								<span style="width:50px;text-align:right;display:inline-block;">OR:</span>
								<span id="orn"></span>
							</td>
						</tr>
    					<tr>
							<td colspan="4" class="ui-text-center">-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --</td>
    					</tr>
    					<tr>
    						<td style="width:10%;"><strong class="ui-text-center">QTY</strong></td>
    						<td style="width:65%;"><strong class="ui-text-center">DESC</strong></td>
    						<td style="width:10%;"><strong class="ui-text-center">PRC</strong></td>
    						<td style="width:15%;"><strong class="ui-text-center">AMT</strong></td>
    					</tr>
    					<tr id="rctitem">
							<td colspan="4" class="ui-text-center">-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --</td>
    					</tr>
    					<tr>
							<td colspan="4" class="ui-text-center">-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --</td>
    					</tr>
    					<tr style="height:10px">
    						<td colspan="2" style="text-align:right;font-weight:700;">TOTAL:</td>
    						<td colspan="2" style="text-align:right;font-weight:700;">&#8369;<span></span><span class="totalprc">0.00</span></td>
    					</tr>
    					<tr style="height:10px;display:none;" class="discounted">
    						<td colspan="2" style="text-align:right;">Discount:</td>
    						<td colspan="2" style="text-align:right;font-weight:700;font-style:italic;"><span class="totalprc2">0.00</span>%</td>
    					</tr>
    					<tr style="height:10px">
    						<td colspan="2" style="text-align:right;">Amount Paid:</td>
    						<td colspan="2" style="text-align:right;">&#8369;<span class="amtpaid">0.00</span></td>
    					</tr>
    					<tr style="height:10px">
    						<td colspan="2" style="text-align:right;">Change:</td>
    						<td colspan="2" style="text-align:right;">&#8369;<span class="amtchange">0.00</span></td>
    					</tr>
    					<tr style="height:10px">
    						<td colspan="2" style="text-align:right;">Total Items:</td>
    						<td colspan="2" style="text-align:right;"><span class="totalqty">0</span></td>
    					</tr>
    					<tr>
							<td colspan="4" class="ui-text-center">-- -- -- -- -- -- -- -- -- -- -- -- --</td>
    					</tr>
    					<tr>
							<td colspan="4" class="ui-text-center">-OFFICIAL RECEIPT-</td>
    					</tr>
    					<tr>
							<td colspan="4" class="ui-text-center">THANK YOU AND COME AGAIN</td>
    					</tr>
    				</tbody>
    			</table>
			</div>
		</div>
		<div style="position:absolute;width:2in;height:auto;background:#fff;display:none;" id="receipt2">
           	<style tyle="text/css">
            <!--
            @page { size:8.5in 11in; margin: .39in; }
			.receipt2 { width:8.5in; height:auto; margin: .39in;}
			.receipt2 .ui-text-center { text-align:center;display:block;width:100%; }
			.receipt2, .receipt2 table { font-size:14px; font-family: Verdana; }
			.receipt2 small{ margin:0px;font-size: 14px; font-family: Verdana; }
			.receipt2 .clear{ display:block;clear:both; }
			.receipt2 .tdiscount{display:none;}
			td.b1{ border:1px solid #000; }
			td.b2{ border-bottom:1px solid #000; }
            -->
            </style>
			<div class="receipt2">
    			<h4 class="ui-text-center" style="font-size: 12px;margin: 0px;">LVT GENERAL MERCHANDISE</h4>
    			<small class="ui-text-center">General Market, Nalasin,</small>
				<small class="ui-text-center">Balaoan, La Union</small>
    			<small class="ui-text-center">Ligaya B. Teofilo - Prop.</small>
    			<small class="ui-text-center">639189650271</small>
				<h2 class="ui-text-center">Sales Receipt</h2>
    			<table style="width:95%;border-collapse: collapse;" cellpadding="2" cellspacing="0">
    				<thead>
    					<tr>
    						<th></th>
    						<th></th>
    						<th></th>
    						<th></th>
    					</tr>
    				</thead>
    				<tbody id="rcptitems">
						<tr>
							<td colspan="2">
								<span style="width:100px;text-align:left;display:inline-block;">Receipt # :</span>
								<span id="orn2"></span>
							</td>
							<td colspan="2">
								Date: <?php echo date("Y-m-d") ?>
							</td>
						</tr>
						<tr>
							<td>
								<span style="width:100px;text-align:left;display:inline-block;">Issued By:</span>
							</td>
							<td colspan="3"><?php echo $login->userid; ?></td>
						</tr>
						<tr>
							<td>
								<span style="width:100px;text-align:left;display:inline-block;">Issued To:</span>
								
							</td>
							<td colspan="3"><span id="custo"></span></td>
						</tr>
						<tr>
							<td>
								<span style="width:100px;text-align:left;display:inline-block;">Address:</span>
								
							</td>
							<td colspan="3"><span id="cusadd"></span></td>
						</tr>
    					<tr>
							<td colspan="4" class="ui-text-center">&nbsp;</td>
    					</tr>
    					<tr>
    						<td style="width:10%;" class="b1"><strong class="ui-text-center">QTY</strong></td>
    						<td style="width:65%;" class="b1"><strong class="ui-text-center">DESC</strong></td>
    						<td style="width:10%;" class="b1"><strong class="ui-text-center">PRICE</strong></td>
    						<td style="width:15%;" class="b1"><strong class="ui-text-center">AMOUNT</strong></td>
    					</tr>
						<?php for($a=0; $a<20; $a++){ ?>
    					<tr class="rcpitems">
    						<td style="width:10%;" class="b1 ui-text-center">&nbsp;</td>
    						<td style="width:65%;" class="b1">&nbsp;</td>
    						<td style="width:10%;" class="b1 ui-text-center">&nbsp;</td>
    						<td style="width:15%;" class="b1 ui-text-center">&nbsp;</td>
    					</tr>
						<?php } ?>
    					<tr>
							<td colspan="4" class="ui-text-center">&nbsp;</td>
    					</tr>
    					<tr style="height:10px">
    						<td colspan="2" style="text-align:right;font-weight:700;">TOTAL:</td>
    						<td colspan="2" class="ui-text-center" style="font-weight:700;">&#8369;<span></span><span class="totalprc">0.00</span></td>
    					</tr>
    					<tr style="height:10px;display:none;" class="discounted">
    						<td colspan="2" style="text-align:right;">Discount:</td>
    						<td colspan="2"  class="ui-text-center" style="font-weight:700;font-style:italic;"><span class="totalprc2">0.00</span>%</td>
    					</tr>
    					<tr style="height:10px">
    						<td colspan="2" style="text-align:right;">Amount Paid:</td>
    						<td colspan="2" class="b2" style="text-align:left;">&#8369;</td>
    					</tr>
    					<tr style="height:10px">
    						<td colspan="2" style="text-align:right;">Change:</td>
    						<td colspan="2" class="b2" style="text-align:left;">&#8369;</td>
    					</tr>
    					<tr style="height:10px">
    						<td colspan="2" style="text-align:right;">Total Items:</td>
    						<td colspan="2" class="ui-text-center"><span class="totalqty">0</span></td>
    					</tr>
    					<tr>
							<td colspan="4" class="ui-text-center">&nbsp;</td>
    					</tr>
    					<tr>
							<td colspan="4" class="ui-text-center">&nbsp;</td>
    					</tr>
    					<tr>
							<td colspan="2" style="text-align:right;">Received by:</td>
							<td colspan="2" class="b2"></td>
    					</tr>
    					<tr>
							<td colspan="4" class="ui-text-center">&nbsp;</td>
    					</tr>
    					<tr>
							<td colspan="4" class="ui-text-center">&nbsp;</td>
    					</tr>
    					<tr>
							<td colspan="4" class="ui-text-center">THANK YOU AND COME AGAIN</td>
    					</tr>
    				</tbody>
    			</table>
			</div>
		</div>
		<div id="form_credit" title="Credits">
		</div>
		<div id="form_search_customer" title="Customers">
		</div>
		<div id="form_new_customer" title="New Customer">
		</div>
		<script>
		$(document).ready(function(){
			$('#branding #site_logo').parent().parent().css('margin-top','-40px').show();
			$('#branding #cart_nav').hide();
			$('#branding .grid_3 .search').hide();
			$('#branding .private ul').children().hide();
			$('#branding .private ul li:nth-child(5)').show();
			$('#branding .private ul li:nth-child(6)').show();
			
			$('#block_nav_primary').css('background', '#f5f7f9');
			$('#branding .private ul li:last-child').show().parent().parent().css({"margin-right": "-260px", "margin-top": "-5px"}).parent().css('height','10px');
			$('header#branding').css('height','50px');
			$('.phone_top').parent().css('visibility','hidden');
			$('#header-top').hide().parent().css('padding-top','10px');
			$('#sale-type').selectBox().change( function() { 
			    	$('#list-item tbody tr').remove();
					$('.rcptitem').remove();
        			$('#amtpay').val('0.00');
        			$('#amtdisc').val('0.00');
					$('#amtchange').val('0.00');
        			$('.amtpaid').html(formatCurrency($(this).val()));
					img_fix();
					$('#item_preview img').attr('src','#');
					recomp();
					$('#itemcredit').attr('disabled',$('#sale-type').val()==0);
					if($('#sale-type').val()==0){
						$('.ccustomer').hide();
						$('#itempay').attr('disabled', false);
						$('#amtpay').attr('disabled', false);
					}else{
						$('#ccustomer2').val('').attr('aid','').attr('address','');
						$('.ccustomer').fadeIn();
						$('#itempay').attr('disabled', true);
						$('#amtpay').attr('disabled', true);
					}
					$('.rcpitems td').each(function(){$(this).html('&nbsp;');});
			 } );
			$('#sel-category').selectBox().change( function() {
				var x = $(this); 
				var base = 0;
				var sel = x.val();
				x.children().each(function(){
					if($(this).val() == x.val())
						base = $(this).attr('base');
				});
				if(base>0 || sel < 0){
					getListings($('#item-search').val());
					return;
				}
				x.attr('icid')
				$.post('?module=pos&action=inventory&action2=category&ajax=1',{getlist:1,getlistid:sel},function(data){
    			 	x.selectBox('destroy');
					var h = '<option value="-1" base="0">Select Categories</option>' + data;
					if(base)
						h += '<option value="0">Back</option>';
					else
						getListings($('#item-search').val());
    			 	x.html(h);
    			 	x.selectBox();
    			 	setTimeout(function(){x.selectBox('open');},100);
                    $('.selectBox-dropdown-menu').click(function(e) {
        				e.stopPropagation();
                    });
				});
			});
			$('#form_credit').dialog({
				autoOpen: false,
      			height: 520,
      			width: 850,
				resizable: false,
            	hide: {
                    effect: "fade",
                    duration: 400
                }
			});
			$('#form_search_customer').dialog({
				autoOpen: false,
      			height: 400,
      			width: 850,
				resizable: false,
            	hide: {
                    effect: "fade",
                    duration: 400
                }
			});
			var wh = $(window).height()-250;
			var ww = $(window).width()-180;
			$('#item_preview').dialog({
				autoOpen: true,
      			height: 220,
      			width: 180,
				resizable: false,
				position:[ww,wh],
            	hide: {
                    effect: "fade",
                    duration: 400
                }
			});
			
			$('#item_keypad').dialog({
				autoOpen: false,
      			height: 345,
      			width: 310,
				resizable: false,
				position:[ww,wh],
            	hide: {
                    effect: "fade",
                    duration: 400
                }
			});
			$('.sort_up').click(function(){
				getListings($('#item-search').val());
			});
			var getListings = function(key){
				var sort = $('.sort_up').attr('flag');
				var cat = $('#sel-category').val();
				var type = $('#sale-type').val();
				$('#sel-category').children().each(function(){
					if($(this).val() == cat && $(this).attr('base') == '0')
						cat = 0;
				});
				$.post('?module=pos&action=sales&ajax=1',{getlist:1,key:key,cat:cat,sort:sort,type:type}, function(data){
					if($('#search-panel').hasClass('panel-open')){
						$('#searches').hide().fadeIn('slow').html(data);
						$('#searches tr').dblclick(function(){
							var e = jQuery.Event("keypress");
                            e.which = 13; //choose the one you want
                            e.keyCode = 13;
							$('#search-box').val($(this).attr('iid')).trigger(e);
						}); 
					}
				});
			};
			$('#search-box').keypress(function(event) {
                if ( event.which == 13 ) {
                	event.preventDefault();
					var isWalkin = $('#sale-type').val()==0;
					$.post('?module=pos&action=sales&action2=search&ajax=1',{key:$(this).val()},function(data){
						if(data == "")
							return;
						if(data == "0x10"){
							alert("Out of Stock!");
							return;
						}
						var js_object = data.split(',');
						console.log(js_object);
						var id = js_object[0];
						var name = js_object[2];
						var price = isWalkin ? js_object[8] : js_object[10];
						var barcode = js_object[6];
						var unit = isWalkin ? js_object[12] : js_object[14];
						var per_unit = isWalkin ? 1 : js_object[16];
						var per_unit2 = js_object[16];
						var mqty = js_object[4]/per_unit;
						var reorder = js_object[18];
						var found = false;
						
						var qty = 0;
						var isChecked = $('#togqty').attr('checked')?true:false;
						if(!isChecked){
    						do{
    							qty = prompt("How many?")*1;
								if(qty==0 || qty<=0.9)
									return;
								if(qty > mqty)
									alert('Not enough stock. Try smaller quantity.');
								if(isNaN(qty))
									alert('Invalid value.');
    						}while(!(qty > 0 && qty <= mqty) || isNaN(qty));
    						
    						if(!(qty > 0 && qty <= mqty)){
    							return;
    						}
						}else
						{
							qty = 1;
						}
						var item = '<tr class="i' + id +  '" iid="' + id +  '" quantity="' + mqty + '" price="' + formatCurrency(price) + '" per="' + per_unit + '" per2="' + per_unit2 + '" iname="' + name + '" reorder="' + reorder + '">' +
                        '	<td style="width: 40px"><input type="checkbox" class="niceCheck"  /></td>' +
                        '	<td style="width: 30px;">' + barcode + '</td>' +
                        '	<td style="width: 250px;">' + name +  '</td>' +
                        '	<td style="width: 100px;">' + unit + (isWalkin ? '' : '('+per_unit+')') +  '</td>' +
                        '	<td style="width: 50px;" class="askqty">' + qty + '</td>' +
                        '	<td style="width: 100px;">' + formatCurrency(price, true) + '</td>' +
                        '	<td style="width: 100px;">&#8369;' + formatCurrency(qty * formatCurrency(price), true) + '</td>' +
        				'</tr>';
						var item2 = '<tr class="i' + id +  ' rcptitem">' +
                        '	<td style="width: 50px;" class="ui-text-center">' + qty +  '</td>' +
                        '	<td style="width: 250px;">' + name +  '</td>' +
                        '	<td style="width: 100px;" class="ui-text-center">' + formatCurrency(price, true) + '</td>' +
                        '	<td style="width: 100px;" class="ui-text-center">' + formatCurrency(qty * formatCurrency(price), true) + '</td>' +
        				'</tr>';
						$('#list-item tbody tr').each(function(){
							if($(this).attr("iid") == id && !found){
								found = true;
								qty2 = $(this).find('td:nth-child(5)').html()*1;
								if(qty2 >= mqty){
									alert("Not enough stock.");
									return;
								}
								$('#rcptitems .i' + id).find('td:nth-child(1)').html(qty2+qty);
								$('#rcptitems .i' + id).find('td:nth-child(4)').html(formatCurrency((qty2+qty)*formatCurrency(price), true));
								$(this).find('td:nth-child(5)').html(qty2+qty);
								$(this).find('td:nth-child(7)').html("&#8369;"+formatCurrency((qty2+qty)*formatCurrency(price), true));

      							$('.rcpitems.ii' + id).find('td:first-child').html(qty2+qty);
      							$('.rcpitems.ii' + id).find('td:last-child').html(formatCurrency((qty2+qty)*formatCurrency(price)));
							}
						});
						if(!found){
							$('#rctitem').after(item2);
        					$('#list-item tbody').prepend(item);
        					$('#list-item tbody tr:first-child').hide().fadeIn('slow');
        					$("#list-item .niceCheck").each(function() {
        						changeCheckStart($(this));
        					});
    						if ($('#item_preview').dialog('isOpen')===false)
    							$('#item_preview').dialog('open');		
    						$('#item_preview img').attr('src','?module=photo&get=thumbnail&from=item_details&id=' + id + '&name=iid&ajax=true').parent().hide().fadeIn('slow');		
							var ok = false;
    						$('.rcpitems').each(function(){
    							if(!ok){
      								if($(this).find('td:first-child').html() == '&nbsp;'){
										$(this).addClass('ii' + id);
      									$(this).find('td:first-child').html(qty);
      									$(this).find('td:nth-child(2)').html(name);
      									$(this).find('td:nth-child(3)').html(formatCurrency(price, true));
      									$(this).find('td:last-child').html(formatCurrency(qty * formatCurrency(price), true));
    									ok = true;
      								}
    							}
    						});
						}
						recomp();
						refuncask();
					});
					$(this).val("");
					if($('#hidesel').is(':checked'))
						$('#search-panel').removeClass('panel-open');
					else if($('#search-panel').hasClass('panel-open')){
						setTimeout(function(){$('#search-panel').css('opacity','1');},800);
						$('#search-panel').css('opacity','0.3');
					}
                }
			});
			$('#search-box').focus().blur(function(){
				$(this).hide().fadeIn(500,function(){
					if(!($('#amtpay').is(":focus")) && !($('#amtdisc').is(":focus")) && !($('#item-search').is(":focus")) && !($('.askqty').find('input').is(":focus")) && !($('#ccustomer2').is(":focus")) && !($('#csearch').is(":focus")) && !($('#cussearch').is(":focus")) )
						$(this).focus();
				});
			});
			$('#amtpay, #amtdisc, #search-item').click(function(){
				$(this).select();
			});
			var recomp = function(){
				var total = 0;
				var total2 = 0.0;				
				$('#list-item tbody tr').each(function(){
					total += $(this).find('td:nth-child(5)').html()*1;
					price = $(this).attr('price');
					total2 += $(this).find('td:nth-child(5)').html()*price;
				});
				$('.totalqty').html(total);
				$('.totalprc').html(formatCurrency(total2, true)).prev().html('');
				if($('#amtdisc').val()*1 > 0)
					$('.totalprc').addClass('tdiscount').prev().html(formatCurrency((100-$('#amtdisc').val())*toNumber($('.totalprc').html())/100, true));
				else
					$('.totalprc').removeClass('tdiscount');
				var change = $('#amtpay').val()*1-toNumber($('.totalprc').html());
				if($('.totalprc').prev().html() != '')
					change = $('#amtpay').val()*1-toNumber($('.totalprc').html());
				$('#amtchange').val(formatCurrency(change>0 ? change : 0, true));
				$('.amtchange').html($('#amtchange').val());
				
				if($('#list-item tbody tr').length > 0 && $('#sale-type').val() == 1)
 					$('#itemcredit').val('Issue');
 				else
 					$('#itemcredit').val('Credit List');
			};
			
			var removeitem = function(){
				$('#list-item tbody tr').each(function(){
					if($(this).find('input').attr('checked') || $(this).find('td span.niceCheck').hasClass('niceChecked')){
						$('.i'+$(this).attr('iid')).fadeOut('slow', function(){$(this).remove();recomp();})
						$('.ii'+$(this).attr('iid')).children('td').each(function(){
							$(this).html('&nbsp');
						});
						$('.ii'+$(this).attr('iid')).removeClass('ii'+$(this).attr('iid'));
					}
				});
				img_fix();
				recomp();
				$('#item_preview img').attr('src','#');
			};
			$('#itemdel').click(function(){removeitem();});
			var pay = function(){
				pay(0);
			};
			var pay = function(credit){
				name = $('#ccustomer2').val();	
				address = $('#ccustomer2').attr('address');
				aid = 10000;
				$('#custo').text('');
				$('#cusadd').text('');
				if($('#ccustomer2').attr('aid') > 0)
					aid = $('#ccustomer2').attr('aid');
				$.post('?module=pos&action=sales&action2=payment&ajax=1',{getor:1, credit:credit, name:name, aid:aid},function(data){
					var count = 0;
					
					$('#custo').text(name);
					$('#cusadd').text(address);
    				$('#list-item tbody tr').each(function(){
                    	id = $(this).attr('iid');
                    	qy = $(this).find('td:nth-child(5)').html()*1;
                    	ss = formatCurrency($(this).attr('price')*qy);
                    	paid = $('#amtpay').val();
                    	dscnt = $('#amtdisc').val();
                    	per_unit = $(this).attr('per');
                    	per_unit2 = $(this).attr('per2');
						orn = data.split(':')[0];
						iscid = data.split(':')[1];
						reorder = $(this).attr('reorder');
                    	qtyy = $(this).attr('quantity');
                    	name = $(this).attr('iname');	$.post('?module=pos&action=sales&action2=payment&ajax=1',{orn:orn,iid:id,sales:ss,qty:qy,amt:paid,dscnt:dscnt,iscid:iscid,name:name, per:per_unit},function(data){
    						console.log(data);
    					});
    					$(this).remove();
						$('#ccustomer2').val('');
						if(reorder*per_unit2 >= (qtyy-qy)){
							set_notif('warning', "<strong>" + name + "</strong> has low stock level. <a class='toast-close reorder-item' iid='" + id + "' href='?module=pos&action=inventory&trans=reorder&keyid=" + id + "' style='display: inline-block;' target='_blank'>Click</a> to order.", '', 0);
							count++;
						}
    				});
					if(count>0)
						set_notif('checkscript', ' ', 'check_stock();', 0, -1);
					if($('#sale-type').val() == 1)
						set_notif('checkscript', ' ', 'check_unpaid();', 0, -1);
					img_fix();
					$('#item_preview img').attr('src','#');	
  					printReciept(orn);
					$('.rcpitems td').each(function(){$(this).html('&nbsp;');});
        			$('#amtpay').val('0.00');
        			$('#amtdisc').val('0.00');
					$('#amtchange').val('0.00');
        			$('.amtpaid').html(formatCurrency($(this).val()));
					$('#ccustomer2').val('').attr('aid','').attr('address','');
					recomp();
				});
			};
			$('#itempay').click(function(e){
				if($(this).attr('disabled'))
					return;
				var cash = $('#amtpay').val();
				var total = toNumber($('.totalprc').html());
				if(cash == 0 || $('#list-item tbody tr').length == 0)
					return;
				if(toNumber($('.totalprc').prev().html()) > 0)
					total = toNumber($('.totalprc').prev().html());
				if(isNaN($('#amtpay').val())){
					alert("Invalid input.");
					$('#amtpay').val(0);
					return;
				}
				if(cash < total){
					alert("Insuficient cash.");
					return;
				}
				pay();
			});
			var printReciept = function (or){
				if($('#sale-type').val() == 1){
    				$('#orn2').html(createOR(or));  
    				html = $('#receipt2').html();
				}else{
    				$('#orn').html(createOR(or));  
    				html = $('#receipt').html();
				}
				printDocument(html);
				$('.rcptitem').remove();
				$('#orn, #orn2').html('');
    			recomp();
				$('#search-box').focus();
            }
			$('#amtpay').keyup(function(event) {
				//$(this).val(formatCurrency($(this).val()));
				var change = $(this).val()*1-toNumber($('.totalprc').html());
				if($('.totalprc').prev().html() != '')
					change = $(this).val()*1-toNumber($('.totalprc').prev().html());
				$('#amtchange').val(formatCurrency(change>0 ? change : 0, true));
				$('.amtchange').html($('#amtchange').val());
				$('.amtpaid').html(formatCurrency($(this).val()));
                if ( event.which == 13 ) {
					$('#itempay').trigger('click');
				}
			}).blur(function(){$('#search-box').focus();$(this).val(formatCurrency($(this).val()));recomp();});
			
			$('#item-search').blur(function(){
				$('#search-box').focus();
			}).keyup(function(){
				getListings($(this).val());
			});
			
			$('#amtdisc').keyup(function(){
				var d = toNumber($(this).val());
				if(d > 100){
					$(this).val(100);
				}
				if(d < 0){
					$(this).val(0);
				}
				if(d > 0){
					$('.discounted').fadeIn('slow');
				}else{
					$('.discounted').hide();
				}
				$('.totalprc2').html($(this).val());
			}).blur(function(){$(this).val(formatCurrency($(this).val()));recomp();});
			var createOR = function(or){
				max = 12;
            	ornum = '#';
            	max -= or.split('').length;
            	if (max < 0) max = 0;
            	for (u=0; u<max; u++)
            	{
            		ornum = ornum + '0';
            	}
            	return ornum + or;
			};
			$('#chksel').click(function(){
				var checkk = $('#chksel span').hasClass('niceChecked');
				if(checkk)
					$('#list-item tbody tr td span.niceCheck').addClass('niceChecked');
				else
					$('#list-item tbody tr td span.niceCheck').removeClass('niceChecked');
			});
			$('#search-btn').click(function(e){
				e.preventDefault();
				$('#search-panel').toggleClass('panel-open');
				getListings('');
				if(!$('#search-panel').hasClass('panel-open')){
					$('#item-search').val('');
    				$.post('?module=pos&action=inventory&action2=category&ajax=1',{getlist:1,getlistid:0},function(data){
        			 	$('#sel-category').selectBox('destroy');
    					var h = '<option value="0" icid="-1">Select Categories</option>' + data;
        			 	$('#sel-category').html(h);
        			 	$('#sel-category').selectBox();
						$('.selectBox-dropdown-menu').click(function(e) {
							e.stopPropagation();
            			});
    				});
				}
			});
			
			$('body').click(function() {
				if($('#search-panel').hasClass('panel-open')){
					$('#search-panel').removeClass('panel-open');
					$('#item-search').val('');
    				$.post('?module=pos&action=inventory&action2=category&ajax=1',{getlist:1,getlistid:0},function(data){
        			 	$('#sel-category').selectBox('destroy');
    					var h = '<option value="0" icid="-1">Select Categories</option>' + data;
        			 	$('#sel-category').html(h);
        			 	$('#sel-category').selectBox();
						$('.selectBox-dropdown-menu').click(function(e) {
							e.stopPropagation();
            			});
    				});
				}
			});
            $('#search-panel, .selectBox-dropdown-menu').click(function(e) {
				e.stopPropagation();
            });
			
			$('.sort_up').click(function(){
				if($(this).attr('flag') == 0){
					$(this).html('&#8595;');
					$(this).attr('flag', 1);
				}else{
					$(this).html('&#8593;');
					$(this).attr('flag', 0);
				}
			});
			
			var refuncask = function(){
				$('.askqty').click(function(){
					if($(this).find('input').length == 0){
						$(this).html('<input class="ui-text-center" type="text" value="' + $(this).html() + '" style="width:90%" />');
						$(this).attr('qty',$(this).find('input').val());
					}
					$(this).find('input').focus().select().blur(function(){
						if(isNaN($(this).val()))
							$(this).val($(this).parent().attr('qty'));
						if($(this).val() < 1)
							$(this).val(1);
						if($(this).val()*1 > $(this).parent().parent().attr('quantity')*1){
							alert('Not enough stock. Try smaller quantity.');
							$(this).val($(this).parent().attr('qty'));
						}				
						var id = $(this).parent().parent().attr('iid');
						var price = $(this).parent().parent().attr('price');
						$('#rcptitems .i' + id).find('td:nth-child(1)').html($(this).val());
						$('#rcptitems .i' + id).find('td:nth-child(4)').html(formatCurrency(($(this).val())*formatCurrency(price), true));	$(this).parent().parent().find('td:nth-child(7)').html("&#8369;"+formatCurrency(($(this).val())*formatCurrency(price), true));
    					$(this).parent().html($(this).val());
    					recomp();
					});
				});
			};
			
			$('#itemcredit').click(function(){
				if($(this).attr('disabled'))
					return;
				var flag = $(this).attr('flag')*1;
				if($(this).val() != 'Credit List'){
					if($('#list-item tbody tr').length>0){
						if($('#ccustomer2').val().length == 0){
							alert('Customer name is blank.');
							return;
						}
						pay(1);
					}
				}else{
    				$.post('?module=pos&action=sales&action2=credit&ajax=1',function(data){
    					$('#form_credit').html(data);
						if(flag > 0){
							$('#datepick1').val('1970-01-01');
							$('#cshow option[value=' + flag + ']').attr('selected', 'selected');
							$('#cshow').trigger('change').next().find('span:first-child').text($('#cshow option[value=' + flag + ']').text());
							$(this).attr('flag', 0);
						}
    					var e = jQuery.Event("keypress");
    					e.which = 13; //choose the one you want
    					e.keyCode = 13;
    					$('#csearch').trigger(e);
    					$('#form_credit').dialog('open');
    				});
				}
			});
			$('#ccustomer2').change(function(){
				$('#custo').html($(this).val());
			});
			/*$('#ccustomer2').autocomplete({
				source: "?module=login&action=search&ajax=1",
				minLength: 1,
				select: function( event, ui ) {
                	console.log( ui.item ?
					"Selected: " + ui.item.value + " aka " + ui.item.id :
					"Nothing selected, input was " + this.value );
					}
            });*/
			$('#ret-item').click(function(e){
				e.preventDefault();	
				$.post('?module=pos&action=inventory&action2=return&ajax=true', function(data) {
    				$('#dialog-form-all').html(data);
					$('#dialog-form-all').dialog({
      					height: 510,
      					width: 600,
      					modal: true,
						resizable: false
					});
					$('#ui-dialog-title-dialog-form-all').html('Return').parent().parent().css('overflow','hidden');
					$('#dialog-form-all').dialog('open');
    			});
				return false;
			});
			$('#searchc').click(function(){
				$.get('?module=login&action=search&ajax=1', function(data){
					$('#form_search_customer').html(data).dialog('open');
					$('#cussearch').attr('target', '#ccustomer2').trigger('keyup');
				});
			});
<?php if($showlist){ ?>
			showlist(<?php echo $showlist; ?>);
<?php } ?>
		});
		var showlist = function(flag){
			$('#sale-type option[value=1]').attr('selected', 'selected');
			$('#sale-type').trigger('change').next().find('span:first-child').text('Wholesale');
			$('#itemcredit').attr('disabled', false).attr('flag', flag).trigger('click');
		};
		</script>